import isPrime from './isPrime'
// 生成数字
export default class {
    constructor(duration = 500) {
        this.duration = duration // 间隔时间
        this.tmer = null
        this.number = 1 // 当前数字
        this.onNumber = (number, isPrime) => { } // 产生数字的回调
    }

    start() {
        if (this.tmer) return
        this.tmer = setInterval(() => {
            this.onNumber(this.number, isPrime(this.number))
            this.number++
        }, this.duration);
    }

    stop() {
        clearInterval(this.tmer)
        this.tmer = null
    }
}